package com.indexingsystem.system.service.impl;

import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.indexingsystem.boss.admin.mapper.RoleOperationsMapper;
import com.indexingsystem.boss.common.PagedResult;
import com.indexingsystem.boss.entity.RoleOperations;
import com.indexingsystem.boss.utils.BeanUtils;
import com.indexingsystem.system.service.IRoleOperationsService;

@Service
public class RoleOperationsServiceImpl implements IRoleOperationsService{

	@Resource
	private RoleOperationsMapper roleOperationsMapper;
	
	@Override
	public int deleteByPrimaryKey(String roleOperationId) {
		return roleOperationsMapper.deleteByPrimaryKey(roleOperationId);
	}

	@Override
	public int insertSelective(RoleOperations record) {
		return roleOperationsMapper.insertSelective(record);
	}

	@Override
	public RoleOperations selectByPrimaryKey(String roleOperationId) {
		return roleOperationsMapper.selectByPrimaryKey(roleOperationId);
	}

	@Override
	public int updateByPrimaryKeySelective(RoleOperations record) {
		return roleOperationsMapper.updateByPrimaryKeySelective(record);
	}
	
    /**
     * 通过角色id查询功能及操作权限id.
     * @param roleId
     * @return
     */
	@Override
	public Set<String> getRoleOperationsByRoleId(String roleId){
		return roleOperationsMapper.getRoleOperationsByRoleId(roleId);
	}
	
	/**
	 * 通过功能id查询操作权限id集合.
	 * 
	 * @param functionId
	 * @return
	 */
	@Override
	public Set<String> getPermissionByFunctionIdOrRoleId(RoleOperations roleOperations){
		return roleOperationsMapper.getPermissionByFunctionIdOrRoleId(roleOperations);
	}

	@Override
	public PagedResult<RoleOperations> selectRoleOperationsList(Integer pageNo, Integer pageSize) {
		pageNo = pageNo == null?1:pageNo;
		pageSize = pageSize == null?10:pageSize;
		//startPage是告诉拦截器说我要开始分页了。分页参数是这两个。
		PageHelper.startPage(pageNo,pageSize);  
		return BeanUtils.toPagedResult(roleOperationsMapper.selectRoleOperationsList());
	}

	@Override
	public int deleteByRoleKey(String roleId) {
		return roleOperationsMapper.deleteByRoleKey(roleId);
	}

	@Override
	public Integer updateByMapSelective(Map<String, Object> str) {
		 return roleOperationsMapper.updateByMapSelective(str);
		
	}

	@Override
	public Integer updateByInMapSelective(Map<String, Object> str) {
		// TODO Auto-generated method stub
		 return roleOperationsMapper.updateByInMapSelective(str);
	}
}